<?php

/**
 * 根据areaId,provinceid,cityid,distinctId提供联动select下拉框
 * @author nbd
 * @since 2016-10-27
 */
namespace app\widgets;

use yii\base\Widget;
use yii\helpers\BaseHtml;

class AreaSelectWidget extends Widget
{
    /**
     * 地区ID
     * @var integer
     */
    public $areaId = 0;

    /**
     * 省份ID
     * @var integer
     */
    public $provinceId = 0;

    /**
     * 城市ID
     * @var integer
     */
    public $cityId = 0;

    /**
     * 地区ID
     * @var integer
     */
    public $distinctId = 0;

    public function run($params = array())
    {
        $content = '';

        $areaData = Yii::$container->get('yii\dbNetPhp\Query')
                ->select('*')
                ->from('area')
                ->all();



        if ($this->area != 0) {
            $listData = Yii::$container->get('yii\dbNetPhp\Query')
                ->select('*')
                ->from($tableName)
                ->where("{$phpPriKey} = :priKey", [':priKey' => $priKeyVal])
                ->all();
        }
        $listDataArr = array();
        foreach ((array) $listData as $valx) {
            $listDataArr[$valx['id']] = $valx['catalog_name'];
        }
        $content .= BaseHtml::dropDownList('provinceId', $search['provinceId'], array(0 => '全部省份') + $listDataArr, array('class' => 'province'));
                               
        $provinceCode = $dataArea['idKeyList'][$val['provinceId']]['c_code'];
        $cityDataArr  = array();
        if (!in_array($provinceCode, Yii::app()->params['phpArea'])) {
            if ($search['provinceId'] != 0) {
                $cityData = Yii::app()->db->createCommand()
                    ->select('id,catalog_name')
                    ->from('bage_catalog_area')
                    ->where('parent_id=:parent_id and c_type=1', array(':parent_id' => $search['provinceId']))
                    ->queryAll();
            }
            foreach ((array) $cityData as $valy) {
                $cityDataArr[$valy['id']] = $valy['catalog_name'];
            }
        }
        ?>
        <?php echo CHtml::dropDownList('cityId', $search['cityId'], array(0 => '不限') + $cityDataArr, array('class' => 'city')); ?>

            }
}
